﻿using System.Web.Mvc;
using DevFramework.MvcUI.Infrastructure;
using Microsoft.Reporting.WebForms;

namespace DevFramework.MvcUI.Controllers
{
    public class ReportController : BaseController
    {
        //
        // GET: /Rapor/
        public ActionResult Index()
        {
            return View();
        }

        [MultipleButton(Name = "action", Argument = "Preview")]
        public ActionResult Preview()
        {
            var localReport = new LocalReport
            {
                ReportPath = Server.MapPath("~/Reports/TestReport.rdlc")
            };

            //localReport.DataSources.Add(new ReportDataSource("DSProducts", _productManager.HepsiniGetir()));

            string reportType = "PDF";
            string mimeType;
            string encoding;
            string fileNameExtension;

            string deviceInfo = string.Empty;

            Warning[] warnings;
            string[] streams;
            byte[] renderedBytes;

            renderedBytes = localReport.Render(
                reportType,
                deviceInfo,
                out mimeType,
                out encoding,
                out fileNameExtension,
                out streams,
                out warnings);

            return File(renderedBytes, mimeType);
        }

        [MultipleButton(Name = "action", Argument = "Save")]
        public ActionResult Save()
        {
            SuccessNotification("Succesfull");
            return RedirectToAction("Index");
        }
	}
}